package com.steak.account.execute;

import com.steak.common.domain.dataobject.tcc.Order;
import com.steak.common.result.Response;
import lombok.AllArgsConstructor;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

/**
 * @author 刘牌
 * @Title:
 * @date 2022/3/721:40
 */
@Component
@AllArgsConstructor
public class AccountExecute {

    final JdbcTemplate jdbcTemplate;

    public Response decreaseBalance(Order order) {
        String sql = "UPDATE account SET balance = ( SELECT accou.balance FROM ( SELECT ( acc.balance - "+order.getMoney()+" ) balance FROM account acc WHERE acc.id = "+order.getUserId()+" ) accou ) WHERE id = "+order.getUserId()+"";
        jdbcTemplate.execute(sql);
        return new Response(200,"decrease balance success",null);
    }
}
